<?php
namespace App\Admin\Metrics;

use App\Models\OrderModel;
use App\Models\User;
use Carbon\Carbon;
use Closure;
use Dcat\Admin\Grid\LazyRenderable as LazyGrid;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Card;
use Illuminate\Contracts\Support\Renderable;

class YesterdayCounts extends Card
{
    /**
     * @param string|Closure|Renderable|LazyWidget $content
     *
     * @return BannerMyAssetsWorth
     */
    public function content($content): YesterdayCounts
    {
        if ($content instanceof LazyGrid) {
            $content->simple();
        }
        $month = date('m');
        $now=Carbon::now()->toDateTimeString();
        $before = "2021-12-26 00:00:00";
        $count_value = OrderModel::query()->whereBetween('created_at', [$before, $now])->whereIn('order_status',[1,3,4,5])->sum('pay_amount');
        $month_value = OrderModel::query()->whereMonth('created_at',$month)->whereIn('order_status',[1,3,4,5])->sum('pay_amount');
        $value = sprintf('%.1f',$count_value/10000);
        $m_value = sprintf('%.1f',$month_value/10000);
        $text = trans('当期成交额/总成交额');
        $html = <<<HTML
<div class="small-box" style="padding:0 20px;height:100px;margin-bottom: 0;border-radius: .25rem;background: url('static/images/blue.png') no-repeat;background-size: 100% 100%;">
    <div class="inner">
        <h4 style="color: white;font-size: 30px;text-shadow: #888888 1px 1px 2px;">{$m_value}万/{$value}万</h4>
        <p style="color: white;text-shadow: #888888 1px 1px 2px;">{$text}</p>
    </div>
</div>
HTML;

        $this->content = $this->formatRenderable($html);
        $this->noPadding();

        return $this;
    }
}
